package org.jparrow.framework.aspect;

import java.lang.reflect.Method;

import org.jparrow.framework.annotation.Aspect;
import org.jparrow.framework.annotation.Controller;
import org.jparrow.framework.proxy.AspectProxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * AOP拦截所有Controller方法
 * 
 * @author supda
 * @Date 2017-3-29 上午10:27:15
 *
 */
@Aspect(Controller.class)
public class ControllerAspect extends AspectProxy{

	private static final Logger LOGGER = LoggerFactory.getLogger(ControllerAspect.class);
	
	private long begin;

	@Override
	public void before(Class<?> cls, Method method, Object[] params) {

		LOGGER.debug("------------begin--------------");
		LOGGER.debug(String.format("class:%s", cls.getName()));
		LOGGER.debug(String.format("method:%s", method.getName()));
		begin = System.currentTimeMillis();
	}

	@Override
	public void after(Class<?> cls, Method method, Object[] params,
			Object result) {
		LOGGER.debug(String.format("time:%dms", (System.currentTimeMillis()-begin)));
		LOGGER.debug("-------------end--------------");
	}
	
	
}
